package com.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dao.mapper.FamilyDao;
import com.dao.mapper.JmtjDao;
import com.domain.Family;
import com.domain.Jmtj;
import com.domain.JmtjJlx;
import com.domain.Jzlx;
import com.service.FamilyService;
import com.service.JmtjService;
import com.utils.ObjectUtils;
@Service(value="jmtjService")
public class JmtjServerImpl implements JmtjService{
	
	@Autowired
	JmtjDao jmtjDao;
	

	@Override
	public void deleteJmtj(int tjbh) {
		jmtjDao.deleteJmtj(tjbh);
		
	}

	@Override
	public int getCount(Map params) {
		int count = 0;
		count = jmtjDao.getCount(params);
		return count;
	}

	@Override
	public List<Map<String,Object>> getJmtj(Map params) {
		List<Map<String,Object>> jmtjs = null;
		jmtjs = jmtjDao.getJmtjs(params);
		return jmtjs;
	}

	@Override
	public Jmtj getJmtjByTjbh(int tjbh) throws Exception{
		return jmtjDao.getJmtjByTjbh(tjbh);
	}

	@Override
	public List<Map<String,Object>> getJmtjJlxByTjbh(int tjbh) throws Exception {
		return jmtjDao.getJmtjJlxByTjbh(tjbh);
	}

	@Override
	public void deleteJmtjJlxByTjbh(int tjbh) {

		jmtjDao.deleteJmtjJlxByTjbh(tjbh);
	}

	@Override
	public void addJmtjJlx(JmtjJlx jmtjjlx) throws Exception {
		jmtjDao.addJmtjJlx(jmtjjlx);
		
	}

	@Override
	public void updateJmtj(Jmtj jmtj) throws Exception {

		jmtjDao.updateJmtj(jmtj);
	}

	@Override
	public void addJmtj(Jmtj jmtj) throws Exception {
		jmtjDao.addJmtj(jmtj);
		
	}

	@Override
	public int getTjbh() throws Exception {
		String param = "";
		jmtjDao.insertNull("");
		Map<String,Object> map = jmtjDao.getNewTjbh(param);
		String s = map.get("tjbh").toString();
		int tjbh = ObjectUtils.getIntVal(s);
		return tjbh;
		
	}

	@Override
	public List<Map<String, Object>> getJmtjInfoByUcode(int ucode) {
		
		List<Map<String,Object>> jmtjInfo = new ArrayList<Map<String,Object>>();
		Map<String,Object> mapjmtj = null;
		List<Map<String,Object>> listTjbh = new ArrayList<Map<String,Object>>();
		
		listTjbh = jmtjDao.getTjbhByJkdah(ucode);
		
		for(int i=0; i<listTjbh.size(); i++){
			int tjbh = ObjectUtils.getIntVal(listTjbh.get(i).get("tjbh").toString());
			
			mapjmtj = jmtjDao.getJmtjByTjbh2(tjbh);//获得体检基本信息
			
			List<Map<String,Object>> listJlx = jmtjDao.getJmtjJlxByTjbh(tjbh);//获得酒类型
			String jlx = "";
			for(int j=0; j<listJlx.size(); j++){
				jlx += ", "+(String)listJlx.get(j).get("mc");
			}
			if(!"".equals(jlx)){
				jlx = jlx.substring(2,jlx.length());
			}
			
			mapjmtj.put("jlx", jlx);
			
			jmtjInfo.add(mapjmtj);
			
		}
		
		return jmtjInfo;
	}
	
	


}
